package controllers;

import java.util.ArrayList;
import java.util.Date;

import model.workersWithData.DBManager;
import model.workersWithData.sort.SortBy;
import model.workersWithData.sort.SortObjectBy;
import entities.IGarage;
import entities.IMaster;
import entities.IOrder;
import entities.OrderStatus;

public class Autoservice implements IAutoservice {

	private DBManager dbManager = new DBManager();
	
	public Integer getEmptyGarage() {
		return dbManager.getEmptyGarage();
	}

	public ArrayList<IOrder> SortOrderByBeginningDate() {
		return dbManager.SortOrder(SortBy.SortBy(SortObjectBy.SORT_ORDERS_BY_BEGINING_DATE));
	}

	public ArrayList<IOrder> SortOrderByDeadlineDate() {
		return dbManager.SortOrder(SortBy.SortBy(SortObjectBy.SORT_ORDERS_BY_DEADLINE_DATE));
	}

	public ArrayList<IOrder> SortOrderByFillingDate() {
		return dbManager.SortOrder(SortBy.SortBy(SortObjectBy.SORT_ORDERS_BY_FILLING_DATE));
	}

	public ArrayList<IOrder> SortOrderByPrice() {
		return dbManager.SortOrder(SortBy.SortBy(SortObjectBy.SORT_ORDERS_BY_PRICE));
	}

	public ArrayList<IMaster> SortMasterByEmployment() {
		return dbManager.SortMaster(SortBy.SortBy(SortObjectBy.SORT_MASTER_BY_EMPLOYMENT));
	}

	public ArrayList<IMaster> SortMasterByName() {
		return dbManager.SortMaster(SortBy.SortBy(SortObjectBy.SORT_MASTER_BY_NAME));
	}

	public ArrayList<IOrder> SortMadingOrderByBeginningDate() {
		return dbManager.SortMadingOrder(SortBy
				.SortBy(SortObjectBy.SORT_ORDERS_BY_BEGINING_DATE));

	}

	public ArrayList<IOrder> SortMadingOrderByDeadlineDate() {
		return dbManager.SortMadingOrder(SortBy
				.SortBy(SortObjectBy.SORT_ORDERS_BY_DEADLINE_DATE));
	}

	public ArrayList<IOrder> SortMadingOrderByFillinggDate() {
		return dbManager.SortMadingOrder(SortBy
				.SortBy(SortObjectBy.SORT_ORDERS_BY_FILLING_DATE));

	}

	public ArrayList<IOrder> SortMadingOrderByPrice() {
		return dbManager.SortMadingOrder(SortBy.SortBy(SortObjectBy.SORT_ORDERS_BY_PRICE));

	}

	public IOrder getOrderByMaster(String masterName) {
		return dbManager.getOrdersByMaster(masterName);
	}

	public IMaster getMasterByOrder(Integer numberOrder) {
		return dbManager.getMastersByOrder(numberOrder);
	}

	public ArrayList<IOrder> SortDeletedOrderByPeriodByBeginningDate(
			Date begin, Date end) {
		return dbManager.SortOrderByPeriod(OrderStatus.DELETED,
				SortBy.SortBy(SortObjectBy.SORT_ORDERS_BY_BEGINING_DATE),
				begin, end);
	}

	public ArrayList<IOrder> SortCanceledOrderByPeriodByBeginningDate(
			Date begin, Date end) {
		return dbManager.SortOrderByPeriod(OrderStatus.CANCELED,
				SortBy.SortBy(SortObjectBy.SORT_ORDERS_BY_BEGINING_DATE),
				begin, end);
	}

	public ArrayList<IOrder> SortMadeOrderByPeriodByBeginningDate(Date begin,
			Date end) {
		return dbManager.SortOrderByPeriod(OrderStatus.MADE,
				SortBy.SortBy(SortObjectBy.SORT_ORDERS_BY_BEGINING_DATE),
				begin, end);
	}

	public ArrayList<IOrder> SortDeletedOrderByPeriodByDeadlineDate(Date begin,
			Date end) {
		return dbManager.SortOrderByPeriod(OrderStatus.DELETED,
				SortBy.SortBy(SortObjectBy.SORT_ORDERS_BY_DEADLINE_DATE),
				begin, end);
	}

	public ArrayList<IOrder> SortCanceledOrderByPeriodByDeadlineDate(
			Date begin, Date end) {
		return dbManager.SortOrderByPeriod(OrderStatus.CANCELED,
				SortBy.SortBy(SortObjectBy.SORT_ORDERS_BY_DEADLINE_DATE),
				begin, end);
	}

	public ArrayList<IOrder> SortMadeOrderByPeriodByDeadlineDate(Date begin,
			Date end) {
		return dbManager.SortOrderByPeriod(OrderStatus.MADE,
				SortBy.SortBy(SortObjectBy.SORT_ORDERS_BY_DEADLINE_DATE),
				begin, end);
	}

	public ArrayList<IOrder> SortDeletedOrderByPeriodByFillingDate(Date begin,
			Date end) {
		return dbManager.SortOrderByPeriod(OrderStatus.DELETED,
				SortBy.SortBy(SortObjectBy.SORT_ORDERS_BY_FILLING_DATE), begin,
				end);
	}

	public ArrayList<IOrder> SortCanceledOrderByPeriodByFillingDate(Date begin,
			Date end) {
		return dbManager.SortOrderByPeriod(OrderStatus.CANCELED,
				SortBy.SortBy(SortObjectBy.SORT_ORDERS_BY_FILLING_DATE), begin,
				end);
	}

	public ArrayList<IOrder> SortMadeOrderByPeriodByFillingDate(Date begin,
			Date end) {
		return dbManager.SortOrderByPeriod(OrderStatus.MADE,
				SortBy.SortBy(SortObjectBy.SORT_ORDERS_BY_FILLING_DATE), begin,
				end);
	}

	public ArrayList<IOrder> SortDeletedOrderByPeriodByPrice(Date begin,
			Date end) {
		return dbManager.SortOrderByPeriod(OrderStatus.DELETED,
				SortBy.SortBy(SortObjectBy.SORT_ORDERS_BY_PRICE), begin, end);
	}

	public ArrayList<IOrder> SortCanceledOrderByPeriodByPrice(Date begin,
			Date end) {
		return dbManager.SortOrderByPeriod(OrderStatus.CANCELED,
				SortBy.SortBy(SortObjectBy.SORT_ORDERS_BY_PRICE), begin, end);
	}

	public ArrayList<IOrder> SortMadeOrderByPeriodByPrice(Date begin,
			Date end) {
		return dbManager.SortOrderByPeriod(OrderStatus.MADE,
				SortBy.SortBy(SortObjectBy.SORT_ORDERS_BY_PRICE), begin, end);
	}

	public Integer getFreePlacesOnDate(Date date) {
		return dbManager.getNumberEmptyPlaces(date);
	}

	public String getNextFreeDate() {
		return dbManager.getNextFreeDate();
	}

	public void addMaster(IMaster master) {
		dbManager.addMaster(master);
	}

	public void deleteMaster(String masterName) {
		dbManager.deleteMaster(masterName);
	}

	public void addGarage(IGarage garage) {
		dbManager.addGarage(garage);
	}

	public void deleteGarage(Integer numberGarage) {
		dbManager.deleteGarage(numberGarage);
	}

	public void addOrder(IOrder order, String masterName, Integer numberGarage) {
		dbManager.addOrder(order, masterName, numberGarage);
	}

	public void markOrderDeleted(Integer numberOrder) {
		dbManager.markOrderDeleted(numberOrder);
	}

	public void markOrderCanceled(Integer numberOrder) {
		dbManager.markOrderCanceled(numberOrder);
	}

	public void markOrderMade(Integer numberOrder) {
		dbManager.markOrderMade(numberOrder);
	}

	public void ShirtTimeOrder(Date newDate, Integer numberOrder) {
		dbManager.ShirtTimeOrder(newDate, numberOrder);
	}

	public IOrder cloneOrder(Integer numberOrder) {
		return dbManager.cloneOrder(numberOrder);
	}

	public void exportGarages() {
		dbManager.exportGarages();

	}

	public void exportMasters() {
		dbManager.exportMasters();

	}

	public void exportOrders() {
		dbManager.exportOrders();
	}

	public void importGarages() {
		dbManager.importGarages();
	}

	public void importMasters() {
		dbManager.importMasters();
	}

	public void importOrders() {
		dbManager.importOrders();
	}

	public void resaveData() {
		dbManager.saveData();
	}

}
